﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VgoCardChange.Models;
using VgoCardChange.Models.Objects;

namespace VgoCardChange.Controllers
{
    public class ItemsController : Controller
    {
        //
        // GET: /Items/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetItems()
        {
            ItemsModels ItMd = new ItemsModels();
            List<Items> listitem = new List<Items>();
            listitem = ItMd.GetItems();
            ViewData["listitem"]=listitem;
            return View();
        }
        public ActionResult CreateItems()
        {
            return View();
        }
        [HttpPost]
        public ActionResult CreateItems(string ItemName, string IsBind, int Quantity)
        {
            ItemsModels ItMd = new ItemsModels();
            Items It = new Items();
            It.ItemName = ItemName;
            It.IsBind=IsBind;
            It.Quantity = Quantity;
            ItMd.CreateItems(It);
            return RedirectToAction("GetItems");
        }
        public ActionResult EditItems(int ItemID)
        {
            ItemsModels ItMd = new ItemsModels();
            List<Items> listitemid = new List<Items>();
            listitemid= ItMd.GetItemID(ItemID);
            ViewData["listitemid"] = listitemid;
            return View(listitemid);
 
        }
        [HttpPost]
        public ActionResult EditItems(int ItemID, string ItemName, string IsBind, int Quantity)
        {
            ItemsModels ItMd = new ItemsModels();
            Items It = new Items();
            It.ItemID = ItemID;
            It.ItemName = ItemName;
            It.IsBind = IsBind;
            It.Quantity = Quantity;
            ItMd.EditItems(It);
            return RedirectToAction("GetItems");
 
        }
        public ActionResult DeleteItems(int ItemID)
        {
            ItemsModels ItMd = new ItemsModels();
            List<Items> listitemid = new List<Items>();
            listitemid = ItMd.GetItemID(ItemID);
            ViewData["listitemid"] = listitemid;
            return View(listitemid);
        }
        [HttpPost]
        public ActionResult DeleteItems(int ItemID, FormCollection coll)
        {
            ItemsModels ItMd = new ItemsModels();
            ItMd.DeleteItems(ItemID);
            return RedirectToAction("GetItems");

        }
        public ActionResult SearchItem()
        {
            return View();
        }
        [HttpPost]
        public ActionResult SearchItem(string ItemName)
        {
            ItemsModels ItMd = new ItemsModels();
            List<Items> listserchitem = new List<Items>();
            listserchitem = ItMd.SearchItem(ItemName);
            ViewData["listserchitem"] = listserchitem;
            return View();
 
        }

    }
}
